package com.imc.api.order.controller;

import com.imc.api.order.service.ApiLessonService;
import com.imc.api.order.service.IOrderService;
import com.twp.common.component.process.exception.combo.IComboExecptionForTFunc;
import com.twp.common.tuple.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

/*
 * 类描述：API课程控制类
 * 开发者：tanweiping
 * 创建日期：2018/10/28 21:08
 */
@Slf4j
@RestController
@RequestMapping("/api/public/goods")
public class ApiLessonController {
    @Autowired
    IComboExecptionForTFunc iComboExecptionForTFunc;

    @Autowired
    IOrderService orderService;//订单服务类

    @Autowired
    ApiLessonService apiLessonService;

    /*
     * tanweiping  2018/9/30 17:31
     * 方法描述：获取分页视频
     */
    @GetMapping("/video")
    ResultDTO video(@PageableDefault(size = 4) Pageable pageable) {
        return iComboExecptionForTFunc
                .executeFlow(
                        ResultDTO.builder().build(),
                        t -> {
                            t.setData(apiLessonService.getVideo(pageable));
                        },
                        (e, t) -> {
                            e.printStackTrace();
                            t.setIsSuccess(false);
                            t.setMessage("获取详情失败");
                        }
                );
    }

    /*
     * tanweiping  2018/9/26 10:24
     * 方法描述：查看商品详情
     */
    @GetMapping("/detail/{id}")
    ResultDTO detail(@PathVariable String id) {
        return iComboExecptionForTFunc
                .executeFlow(
                        ResultDTO.builder().build(),
                        t -> {
                            t.setData(orderService.queryDetailsByLessOnId(id, null));
                        },
                        (e, t) -> {
                            e.printStackTrace();
                            t.setIsSuccess(false);
                            t.setMessage("获取详情失败");
                        }
                );
    }

    /*
     * YT  2018/10/28 21:08
     * 方法描述：推荐
     */
    @GetMapping("/recommend")
    ResultDTO recommend(
            @RequestParam(defaultValue = "6", required = false) String sizeCast,
            @RequestParam(defaultValue = "6", required = false) String sizeVideo
    ) {
        return iComboExecptionForTFunc
                .executeFlow(
                        ResultDTO.builder().build(),
                        t -> {
                            t.setData(
                                    apiLessonService.getRecommendLessonList(Integer.parseInt(sizeCast), Integer.parseInt(sizeVideo))
                            );
                        },
                        (e, t) -> {
                            e.printStackTrace();
                            t.setIsSuccess(false);
                            t.setMessage("获取推荐视频失败");
                        }
                );
    }
}